<!-- Loads initialization file with a couple of variables -->

<%@ include file="../../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Provide Degree - Choose Discipline Page
		</title>
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/expand.css">
	</head>
	<body>
		<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		<div class="message"></div>
		<%	try {
		
			Applicant a = (Applicant)session.getAttribute("applicant");
			
			/** Get list of degrees **/
			
			ArrayList<Degree> dAl = (ArrayList<Degree>)session.getAttribute("degrees");
			
			Degree d = (Degree)session.getAttribute("degree");
			
			/*** Write data from URL to degree object ***/
			
			if(request.getParameter("universityCustom") != null)
			{
				d.setUniversityId(University.storeCustomUniversity(request.getParameter("universityCustom"), d.getLocationId()));
				d.setUniversity(request.getParameter("universityCustom"));	
			}
			else
			{
				d.setUniversity(request.getParameter("university"));
				d.setUniversityId(Integer.parseInt(request.getParameter("universityId")));
			}
			
			/** Store degree to session object **/
			
			session.setAttribute("degree", d);
			
		%>
			<h2>Previous Data:</h2>
			
			<ol class="tree">
				<li><label for="general">General Information</label><input type="checkbox" id="general" />
					<ol> 
						<li>	
							<table>	
								<tr><td>First Name:</td><td><%= a.getFirstName() %></td></tr>
								<tr><td>Middle Initial:</td><td><%= a.getMiddleInitial() %></td></tr>
								<tr><td>Last Name:</td><td><%= a.getName() %></td></tr>
								<tr><td>Country of Citizenship:</td><td><%= a.getCountryOfCitizenship() %></td></tr>
								<tr><td>Country of Residence:</td><td><%= a.getCountryOfResidence() %></td></tr>
								<tr><td>Street:</td><td><%= a.getStreet() %></td></tr>
								<tr><td>City:</td><td><%= a.getCity() %></td></tr>
								<tr><td>ZIP/Postal Code:</td><td><%= a.getZip() %></td></tr>
							<%	
								/*** Determin whether 'state' or 'country phone code' needs to be displayed ***/
							
								if(a.getCountryOfResidence().equals("United States"))
								{
									out.print("<tr><td>State:</td><td>" + a.getState() + "</td></tr>");
								}	
								else
								{
									out.print("<tr><td>Country Phone Code:</td><td>" + a.getCountryPhoneCode() + "</td></tr>");
								}
							%>
								<tr><td>Area code:</td><td><%= a.getAreaCode() %></td></tr>
								<tr><td>Number:</td><td><%= a.getNumber() %></td></tr>
							</table>
						</li>
					</ol>
				</li>
			</ol>
				
				<%
			
				/*** Iterate over amount of degrees and display them ***/	
					
				for(int i = 0; i < dAl.size(); i++)
				{
				
			%>
				<ol class="tree">
					<li><label for="degree<%= i+1 %>">Degree <%= i+1 %></label><input type="checkbox" id="degree<%= i+1 %>" />
						<ol> 
							<li>	
								<table>
									<tr><td>State/Country:</td><td> <%= dAl.get(i).getLocation() %></td></tr>
									<tr><td>University:</td><td> <%= dAl.get(i).getUniversity() %></td></tr>
									<tr><td>Discipline:</td><td> <%= dAl.get(i).getDiscipline() %></td></tr>
									<tr><td>Degree Award:</td><td> <%= dAl.get(i).getMonth() %>/<%= dAl.get(i).getYear() %></td></tr>
									<tr><td>GPA:</td><td> <%= dAl.get(i).getGpa() %></td></tr>
									<tr><td>Title:</td><td> <%= dAl.get(i).getTitle() %></td></tr>
									<tr><td>Transcript:</td><td> <%= dAl.get(i).getTranscription() %></td></tr>
								</table>
							</li>
						</ol>
					</li>
				</ol>
			<% 
				} 
			%>
			
			<ol class="tree">
				<li><label for="degree<%= dAl.size()+1 %>">Degree <%= dAl.size()+1 %></label><input type="checkbox" id="degree<%= dAl.size()+1 %>" />
					<ol> 
						<li>	
							<table>
								<tr><td>State/Country:</td><td> <%= d.getLocation() %></td></tr>
								<tr><td>University:</td><td> <%= d.getUniversity() %></td></tr>
							</table>
						</li>
					</ol>
				</li>
			</ol>
			<hr>
			<br>
			
			Please choose your discipline and provide further information.<br><br>
			
			<form method="GET" action="moreDegrees.jsp">
				<table>	
			<%
					/** Get disciplines **/	
					
						Discipline m = new Discipline();
						ArrayList<Discipline> mAl = m.getDisciplines();
					
						/*** Iterate over all disciplines and display them in a radio button menu ***/
						
						for(int i=0; i<mAl.size(); i++)
						{
							out.println("<tr><td><input type=\"radio\" name=\"discipline\"" + 
										"value=\"" + mAl.get(i).getName() + "\">" + 
										mAl.get(i).getName() + "</td></tr>");
						}
				%>
					<tr><td>If none of the disciplines above is applicable please enter your discipline here: 
						<input name="disciplineCustom" size="40"></td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>Please enter month and year of (expected) degree awarding:</td></tr>
					<tr><td>Month (mm): <input name="degreeAwardMonth" maxlength="2" size="4"> 
					Year (yyyy): <input name="degreeAwardYear" maxlength="4" size="4"></td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>Please enter (expected) GPA: <input name="gpa" size="4"></td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>Please select the title of your degree: 
					<select name="title">
						<option selected>BS</option>
						<option>MS</option>
						<option>PhD</option>
					</select></td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>Upload a transcription of your degree: <input type="file" name="transcript" size="53"></td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td><input type="submit" value="Submit"></td></tr>
				</table>
			</form>
			<%	
				}
				catch(Exception e)
				{
					response.sendRedirect(BASE + "error.jsp");
				}
			%>
		</div>
	</body>
</html>